/* Copyright 2009 (c) ENSI de Bourges
 * 		88 boulevard Lahitolle, 18020 Bourges Cedex, France
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 * \file main.c
 * \brief Source code of the application.
 * \author Steve Dodier <sidnioulz@gmail.com>
 *
 * This file contains the source of the whole application. It should not be
 * modified unless you know what you do.
 */
#include <librsvg/rsvg.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <stdio.h>

#include "application-data.h"
#include "constants.h"
#include "frame-common.h"
#include "frame-new-dialog.h"
#include "frame-private.h"
#include "log-player.h"



/** \fn int main (int argc, char *argv[])
 * \brief The main function.
 *
 * \warning Do not touch the code in this function, except for the customisable
 * part separated with comments.
 *
 * This is the main function. You should use it only to create and initialise
 * frames for testing purpose.
 * @param[in] argc the number of command line arguments
 * @param[in] argv an array containing the arguments
 * @return EXIT_SUCCESS if everything goes well, EXIT_FAILURE otherwise
 */
int main (int argc, char *argv[])
{
	ls_instance_t	*inst			= NULL;
	GtkWidget 		*window 		= NULL;
	GtkWidget		*scroll_area	= NULL;
	
	g_thread_init (NULL);
	gdk_threads_init();
	gdk_threads_enter ();
	gtk_init (&argc, &argv);
	rsvg_init ();
	inst = livesecurity_instance ();

	// The window used by frame developers
	window = (GtkWidget *) gtk_builder_get_object (inst->builder, "els_window");
    g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
    g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);


	// Connecting toolbar buttons to handlers
	g_signal_connect ((GtkWidget *) gtk_builder_get_object (inst->builder, "toolbutton_add"),
						"clicked", G_CALLBACK (frame_on_new), 
						(gpointer) inst->builder);
	g_signal_connect ((GtkWidget *) gtk_builder_get_object (inst->builder, "toolbutton_player"),
						"clicked", G_CALLBACK (toggle_player_panel),
						(gpointer) inst->builder);
	g_signal_connect ((GtkWidget *) gtk_builder_get_object (inst->builder, "toolbutton_quit"),
						"clicked", G_CALLBACK (gtk_main_quit), NULL);


	// We put the widgets in their respective containers
	scroll_area = (GtkWidget *) gtk_builder_get_object (inst->builder, "scroll_area");

	gtk_table_set_row_spacings (GTK_TABLE (inst->table), 10);
	gtk_table_set_col_spacings (GTK_TABLE (inst->table), 10);


	gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll_area), inst->table);


	// Make sure all widgets are shown
	gtk_widget_show_all (window);


	// Hide the player side panel
	toggle_player_panel (GTK_TOOL_BUTTON ((GtkWidget *) gtk_builder_get_object (inst->builder, "toolbutton_player")),
						(gpointer *) inst->builder);
	gtk_main ();

	rsvg_term ();
	livesecurity_instance_free ();
	gdk_threads_leave ();

	return EXIT_SUCCESS;
}
